﻿using System;
using System.Collections.Generic;
using System.Linq;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Audio;
using Microsoft.Xna.Framework.Content;
using Microsoft.Xna.Framework.GamerServices;
using Microsoft.Xna.Framework.Graphics;
using Microsoft.Xna.Framework.Input;
using Microsoft.Xna.Framework.Input.Touch;
using Microsoft.Xna.Framework.Media;
using GameFramework;
using Microsoft.Phone.Shell;
using System.IO.IsolatedStorage;
using System.IO;

namespace GameForKids
{
    // tao mot gamestate quan ly
    public  enum GameState
    {
        Loading,
        Login,
        MainMenu,
        Info,
        Memory,
        AlphabetMemory,
        NumbersMemory,
        SoundMemory,
        Fishtank,
        FindCharacters,
        Puzzle,
        FindSound,
        PackId,
        Billiard,
        DrawNumbers
    }
    
    public class GameForKids : Microsoft.Xna.Framework.Game
    {
        GraphicsDeviceManager graphics;
        SpriteBatch spriteBatch;
        ScreenManager screenManager;

        public static GameState gameState;
        public static string userName="";

        public static string language;
        public static Boolean ISMUSIC = true;

        public const string VIET = "TIENGVIET";
        public const string ANH = "TIENGANH";
        public const string ON = "ON";
        public const string OFF = "OFF";

        public const int WIDTH = 800;
        public const int HEIGHT = 480;
        public const string NameOfFileSetting = "Setting.txt";

        public GameForKids()
        {
            graphics = new GraphicsDeviceManager(this);
            graphics.IsFullScreen = true;
            graphics.PreferredBackBufferHeight = HEIGHT;
            graphics.PreferredBackBufferWidth = WIDTH;
            graphics.SupportedOrientations = DisplayOrientation.LandscapeLeft | DisplayOrientation.LandscapeRight;
            Content.RootDirectory = "Content";
            language = ANH;

            // Frame rate is 30 fps by default for Windows Phone.
            TargetElapsedTime = TimeSpan.FromTicks(333333);

            Initialize();

            // Extend battery life under lock.
            InactiveSleepTime = TimeSpan.FromSeconds(1);
            gameState = GameState.Loading;
            screenManager = new ScreenManager(this);
            Components.Add(screenManager);
            screenManager.AddScreen(new LoadingScreen(), null);
        }


    
        protected override void Initialize()
        {
            // load ngon ngu
            using (IsolatedStorageFile isolatedStorageFile = IsolatedStorageFile.GetUserStoreForApplication())
            {
                if (isolatedStorageFile.FileExists(NameOfFileSetting))
                {
                    using (IsolatedStorageFileStream isfs = isolatedStorageFile.OpenFile(NameOfFileSetting, FileMode.Open))
                    {
                        using (StreamReader reader = new StreamReader(isfs))
                        {
                            while (!reader.EndOfStream)
                            {
                                language = reader.ReadLine();
                                string s = reader.ReadLine();
                                if (s == ON)
                                    ISMUSIC = true;
                                else
                                    ISMUSIC = false;
                            }
                        }
                    }
                }
            }
            base.Initialize();
        }

        protected override void LoadContent()
        {
            spriteBatch = new SpriteBatch(GraphicsDevice);

           

            base.LoadContent();
        }


        protected override void UnloadContent()
        {
        }


        protected override void Update(GameTime gameTime)
        {
            base.Update(gameTime);
        }

        protected override void Draw(GameTime gameTime)
        {
            GraphicsDevice.Clear(new Color(0,0,0));
            base.Draw(gameTime);
        }
    }
}
